﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;


/// <summary>
/// Descripción breve de Utilitarios
/// </summary>
public class Utilitarios
{
    public const string Conexion = "Server=192.168.50.10;UID=sisoper;PWD=sisoper;Database=BDSystem";
    //public const string Conexion = "Server=localhost;UID=sa;PWD=sa0;Database=BDSystem";
    public const string Conexion2 = "Server=192.168.50.10;UID=sisoper;PWD=sisoper;Database=KLegal";
    //public const string Conexion2 = "Server=localhost;UID=sa;PWD=sa0;Database=KLegal";
    public Utilitarios()
    {
        //
        // TODO: Agregar aquí la lógica del constructor
        //


    }
    public string Ceros(int valor, int ctos)
    {
        string cerosn = "0000000000";
        string ceros = cerosn.Substring(0, ctos);
        int valorent = valor;
        string valorceros = valorent.ToString(ceros);
        return valorceros;
    }

    public bool[] leve(int cl)
    {
        int lev = cl;
        bool[] level = new bool[10];
        bool bucle = true;
        while (bucle)
        {
            if (lev >= 256) { level[9] = true; lev = lev - 256; }
            if (lev >= 128) { level[8] = true; lev = lev - 128; }
            if (lev >= 64) { level[7] = true; lev = lev - 64; }
            if (lev >= 32) { level[6] = true; lev = lev - 32; }
            if (lev >= 16) { level[5] = true; lev = lev - 16; }
            if (lev >= 8) { level[4] = true; lev = lev - 8; }
            if (lev >= 4) { level[3] = true; lev = lev - 4; }
            if (lev >= 2) { level[2] = true; lev = lev - 2; }
            if (lev >= 1) { level[1] = true; lev = lev - 1; }
            if (lev <= 0) bucle = false;
        }
        return level;
    }

    public string UserNombre(int UCo)
    {
        string msg = "Select Usuario from SIS_Usuarios where IDU = " + UCo.ToString();
        string rpta;
        SqlConnection CNx3 = new SqlConnection();
        CNx3.ConnectionString = Utilitarios.Conexion;
        CNx3.Open();
        SqlCommand tb = new SqlCommand(msg, CNx3);
        rpta = tb.ExecuteScalar().ToString();
        CNx3.Close();
        return rpta;
    }

    public string UserNombres(int UCo)
    {
        string msg = "Select Nombres from SIS_Usuarios where IDU = " + UCo.ToString();
        string rpta;
        SqlConnection CNx3 = new SqlConnection();
        CNx3.ConnectionString = Utilitarios.Conexion;
        CNx3.Open();
        SqlCommand tb = new SqlCommand(msg, CNx3);
        rpta = tb.ExecuteScalar().ToString();
        CNx3.Close();
        return rpta;
    }

    public string Afecha(string ftt)
    {
        string resp;
        resp = ftt.Substring(3, 2) + "/" + ftt.Substring(0, 2) + ftt.Substring(5, 5);
        //resp = ftt.Substring(0, 2) + "/" + ftt.Substring(3, 2) + ftt.Substring(5, 5) ;
        return resp;
    }
}